authApp.value('page','updata');
authApp.controller("uploadController",function($scope,$http,$location,$getQueryString,$splice,Upload,$timeout, $cookies){

    //上传pdf文件
    $scope.uploadFiles= function(file, errFiles,index) {
        $scope.f = file;
        $scope.errFile = errFiles && errFiles[0];

        if (file) {
            console.log(file);
            file.upload = Upload.upload({
                url: apis.uploadfile,
                data: {file: file}
            });

            file.upload.then(function (response) {
                console.log(response);
                $timeout(function () {
                    if(response.data.code=="000000"){
                        $scope.uploadFileName = response.data.data.url;
                        $scope.uploadUrl = response.data.data.url
                        $scope.saveresponse();
                    }
                    else
                        alert(response.data.errorMsg);
                });
            }, function (response) {
                if (response.status > 0)
                    $scope.errorMsg = response.status + ': ' + response.data;
            }, function (evt) {
                file.progress = Math.min(100, parseInt(100.0 *
                    evt.loaded / evt.total));
            });
        }
    }

    $scope.getAML=function(){
        var id = $cookies.get('account')
        $http({
            method:'post',
            url:apis.queryApplyFileBySchoolId,
            data: {'son_target_id':'', 'schoolId': id},
        }).success(function(response){
            if(response.code=="000000"){
                $scope.uploadFileName = response.data.s_employment_distribution_filepath;
            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("服务器打瞌睡了，请稍等！");
        })
    }

    $scope.getAML();
    $scope.saveresponse = function(){
        $http({
            method:'post',
            url:apis.saveApplyFile,
            data:{
                fileUrl:$scope.uploadUrl,
                'son_target_id': '',
                'schoolId': $cookies.get('account'),
                's_score': ''
            },
        }).success(function(response){
            if(response.code=="000000"){
                //alert(response.errorMsg);
               // $scope.getAML();
            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("服务器打瞌睡了，请稍等！");
        })
    }
})
